package myjava.algorithm.leetcode;

public class MajorElement {
	
	// max
	public static int majorityElement(int[] num) {
		
		int candidate = 0;
		int nTimes,i;
		
		for(i=nTimes = 0;i<num.length;i++)
		{
			if(nTimes == 0)
			{
				candidate = num[i];nTimes = 1;
			}
			else {
				if(candidate == num[i])
					nTimes++;
				else {
					nTimes--;
				}
			}
		}
		
        return candidate;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] a = {3,3,4};
		System.out.println(majorityElement(a));
		
	}

}
